package com.xyc.servlet;


import com.xyc.Untils.MybatisUntils;
import com.xyc.mapper.OrderMapper;
import com.xyc.pojo.Order;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/play")
public class PlayServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("PlayServlet...");

        SqlSession sqlSession = null;
        HttpSession session = req.getSession();

        try {
            sqlSession = MybatisUntils.getSqlSession();
            OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);

            List<Order> orderList = orderMapper.findOrder();
            System.out.println(orderList);
            session.setAttribute("orderList",orderList);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sqlSession.close();
        }

    }
}
